<template>
  <div class="login-box">
    <el-form class="login-form" ref="loginForm" :model="loginForm" :rules="loginFormRules" status-icon >
      <el-form-item prop='userName' label="账号">
        <el-input @keyup.enter.native="loginSub" v-model.trim="loginForm.userName"
                  placeholder="请输入账号" type="text" show-word-limit clearable></el-input>
      </el-form-item>
      <el-form-item prop='password' label="密码">
        <el-input @keyup.enter.native="loginSub" v-model.trim="loginForm.password"
                  placeholder="请输入密码" type="password" show-password clearable></el-input>
      </el-form-item>
      <el-button type="primary" @click='loginSub' class="login-btn">登录</el-button>
    </el-form>

  </div>
</template>

<script>
import { setToken } from "@/utils/auth"
export default {
  data() {
    return {
      loginForm: {
        userName:'admin',
        password:'123456',
      },
      loginFormRules: {
        userName: [{ required: true, message: '请输入账号', trigger: 'blur' }],
        password: [{ required: true, message: '请输入密码', trigger: 'blur' }]
      }
    }
  },
  methods: {
    loginSub() {
      this.$refs.loginForm.validate(async valid => {
        if (valid) {
          setToken('123')
          this.$router.replace('/main')
        }
      })

    },
  }
}
</script>

<style lang="scss" scoped>
.login-box {
  height: 100%;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  margin: auto;
  background: rgba($color: teal, $alpha: 0.3);
  display: flex;
  justify-content: center;
  align-items: center;
  .login-form {
    width: 400px;
    height: 400px;
    background: transparent;
    padding: 50px 40px;
    box-shadow: 0px 0px 15px teal;
    position: relative;
    .login-btn {
      position: absolute;
      right: 40px;
      bottom: 20px;
    }
  }
}
</style>
